<template>
    <div>
        <embed ref="sdkViewer" type='application/npPluginSDK-plugin' id='sdk_viewer' class='plugin' style="position: relative;width: 600px;height: 500px;"/>
        <el-button @click="initPlayer">加载视频</el-button>asdfgddfhjnf
    </div>
</template>

<script>

    export default {
        name: "videoTest",
        components: {},
        data() {
            return {
                //播放控件参数
                cfg: {
                    maxWnd: 64,                       //控件动态创建窗格的个数，不小于最大通道路数,默认64路 (可选)
                    focusColor: 'ffcc00',             //窗格获得焦点时的边框颜色，注意：参数形如'xxxxxx'，为颜色的16进制，以b g r 顺序，而不是r g b (可选)
                    unfocusColor: '747d7d',           //窗格未获得焦点时的边框颜色，注意：参数形如'xxxxxx'，为颜色的16进制，以b g r 顺序，而不是r g b (可选)
                    backgColor: '000000'              //控件背景色，注意：参数形如'xxxxxx'，为颜色的16进制，以b g r 顺序，而不是r g b (可选)
                },
                realPlayCfg: {
                    dwChannelID: 1,
                    dwStreamType: LiveStream.LIVE_STREAM_INDEX_MAIN,
                    dwLinkMode: Protocal.TRANSPROTOCAL_RTPTCP,
                    dwFluency: 0
                },
                sdkViewer: null,
                dev: {
                    userID: "",
                    szIPAddr: "192.168.1.13",
                    dwPort: 80,
                    szUserName: "admin",
                    szPassword: "123456",
                    dwLoginProto: 0
                }
            };
        },
        mounted() {
            if( !this.sdkViewer ){
                this.sdkViewer = document.getElementById( "sdk_viewer" );
            }
        },
        methods: {
            initPlayer: function(){

                this.execFunction( "NetSDKCreateWnd", this.cfg.maxWnd, this.cfg.focusColor, this.cfg.unfocusColor, this.cfg.backgColor );
                this.execFunction("NETDEV_Init", "");
                let retcode = this.execFunction("NetSDKSetPlayWndNum", 1);
                let SDKRet = this.execFunction(pluginInterfce["NETDEV_Login"], JSON.stringify( this.dev ));
                console.log( SDKRet );
                let result = JSON.parse(SDKRet);
                this.dev.userID = result.UserID;
                SDKRet = this.execFunction(pluginInterfce["NETDEV_QueryVideoChl"], this.dev.userID);
                console.log( SDKRet );
                var openretcode = this.execFunction("NETDEV_RealPlay", 0, this.dev.userID, JSON.stringify( this.realPlayCfg ));
                console.log( openretcode );
            },
            setParam: function (param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) {
                var paramObj = [param1, param2, param3, param4, param5, param6, param7, param8, param9, param10];
                return JSON.stringify(paramObj);
            },
            execFunction: function (funcName, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10) {
                var param = this.setParam(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10);
                /* 这里直接用top.JSON，跨域问题，通过将信任站点的设置放在最后调用来解决*/
                var result = JSON.parse(this.sdkViewer.NetSDKExecFun(funcName, param));
                if (result.code !== 0) {
                    return result.code;
                }
                return result.result;
            }
        }
    };
</script>

<style scoped>
    .yard {
        width: calc(100% - 100px);
    }


</style>